<template>
	<view class="approval_apply">
		<xbd-pages-content title="我的审批">
			<template #content>
				<view class="content">
					<uni-list :border="false">
						<xbd-perf-card @clickPreformanceCard="details(item._id,item.performance_statue)" v-for="item in showList" :key="item._id" :myInfo="item"></xbd-perf-card>
						<xbd-null-list v-if="!showList.length"></xbd-null-list>
						<xbd-loading-more :status-num="statusNum" :is-load-more="isLoadMore"></xbd-loading-more>
					</uni-list>

				</view>
			</template>
		</xbd-pages-content>
	</view>
</template>

<script>
	import { Performance } from '@/api/index.js';
	export default {
		data() {
			return {
				search:'',
				statusNum: 0,
				isLoadMore: false,
				type: '',
				total:'',
				showList:[],
				queryInfo:{
					type:"audit",
					page: 1,
					perpage: 10
				}
			};
		},
		methods: {
			// eventCallback(obj) {
			// 	// console.log('我的历史页面', obj);
			// 	// this.showList.forEach(item => {
			// 	// 	if (item._id == obj) {
			// 	// 		item.performance_statue = '1';
			// 	// 	}
			// 	// });
			// 	this.queryInfo.page = 1
			// 	this.getList()
			// 	// 强制刷新回到顶部
			// 	uni.pageScrollTo({
			// 	    scrollTop: 0,
			// 	});
			// },
			// eventCallback2(obj) {
			// 	this.showList = this.showList.filter(item => {
			// 		return +item._id !==  +obj
			// 	})
			// },
			// modifyDetails(val,id){
			// 	console.log('我的历史页面3',val)
			// 	console.log('我的历史页面3',id)
			// 	this.showList.forEach(item => {
			// 		if (item._id == id) {
			// 			item.details = val
			// 			console.log(item.details,'details',val)
			// 		}
			// 	});
			// 	console.log(this.showList,'modifyDetails2')
			// },
			async getList() {
				try {
					this.$showLoading('加载中');
					const res = await Performance.getHistory(this.queryInfo);
					uni.hideLoading();
					if(res.data.success){
						console.log(res,'res')
						this.total = res.data.data.total
						this.total = res.data.data.total;
						this.showList = res.data.data.data
						console.log(this.showList)
						if (res.data.data.data.length === this.queryInfo.perpage) {
							this.isLoadMore = true;
							this.statusNum = 2;
						}
					}else{
						uni.showToast({
								title: res.data.msg,
								icon: 'none',
							})
					}
					
					console.log('list', this.showList)
				} catch (e) {
					uni.hideLoading();
					console.log(e);
				}
			},
			loadmore() {
				if (this.visible) {
			
				} else {
					this.queryInfo.page++;
					this.statusNum = 1;
					this.isLoadMore = true;
					this.loadmoreList();
				}
			},
			// 加载数据
			async loadmoreList() {
				try {
					this.$showLoading('加载中');
					const res = await Performance.getHistory(this.queryInfo);
					console.log(res)
					uni.hideLoading();
					if (res.data.success) {
						this.showList = this.showList.concat(res.data.data.data);
						if (res.data.data.data.length === this.queryInfo.perpage) {
							this.statusNum = 2;
							// this.isLoadMore=false
						} else {
							this.statusNum = 0;
						}
					} else {
						uni.showToast({
								title: res.data.msg,
								icon: 'none',
							})
						this.queryInfo.page--;
						this.statusNum = 0;
					}
				} catch (e) {
					uni.hideLoading();
					this.queryInfo.page--;
					console.log(e);
				}
			},
			details(id,val) {
				uni.navigateTo({
					url: `./auditForm?msg=2&id=${id}&state=${val}`,
				})
			},
			
		},
		onShow(){
			this.queryInfo.page = 1
			this.getList()
			// 强制刷新回到顶部
			uni.pageScrollTo({
			    scrollTop: 0,
			});
		},
		onLoad() {
			// this.getList()
			
			// uni.$on('performancePassed', this.eventCallback);
			// uni.$on('performanceId', this.eventCallback2);
			// uni.$on('refresh', this.eventCallback);
		},
		onUnload() {
			// uni.$off('performancePassed');
			// uni.$off('performanceId');
			// uni.$off('refresh');
		},
		// 触底触发
		onReachBottom() {
			// 当下拉组件显示状态 并且显示不是没有数据了 时才进行下拉加载
			if (this.isLoadMore && this.statusNum !== 0 && this.total/10 >this.queryInfo.page) {
				this.loadmore();
			}
			if(this.total/10 >this.queryInfo.page){
				
			}else{
				this.isLoadMore = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-list {
		background-color: #f8f8f8;
	}
	::v-deep .data-v-1a79304c {
		white-space: nowrap;
	}
	
	::v-deep .uni-easyinput__content {
		border-radius: 8rpx;
		min-height: 32px;
	}
	
	::v-deep .uni-input-wrapper {
		text-align: center;
		white-space: nowrap;
	}
	.choose {
		height: 105px;
		box-sizing: border-box;
		padding: 20px 50rpx;
		font-size: 14px;
		color: #999999;
		background-color: #FFFFFF;

		.two {
			display: flex;
			height: 32px;
			margin-bottom: 16px;
			.select{
				margin-right: 10rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				white-space: nowrap;
				width: 220rpx;
				height: 32px;
				line-height: 32px;
				border-radius: 8rpx;
				border: 1px solid #E9ECF7;
				box-sizing: border-box;
				padding: 0 20rpx 0 20rpx;
				.image{
					transform: rotate(90deg);
					width: 38rpx;
					height: 38rpx;
				}
			}
			.search{
				margin-left: 20rpx;
				height: 32px;
				// align-items: center;
				.image{
					margin-top: 7px;
					width: 36rpx;
					height: 36rpx;
				}
			}
		}
	}
</style>
